import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isEmpty from "lodash/isEmpty";

var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2;

import React, { PureComponent } from 'react';
import { Button, Col, DatePicker, Form, Input, Row, Select } from 'antd';
import moment from 'moment';
import { Bind } from 'lodash-decorators';
import Lov from 'components/Lov';
import { DEFAULT_DATETIME_FORMAT, FORM_COL_4_LAYOUT, SEARCH_FORM_ITEM_LAYOUT, SEARCH_FORM_ROW_LAYOUT } from 'utils/constants';
import intl from 'utils/intl';
import { getDateTimeFormat } from 'utils/utils';
var FormItem = Form.Item;
var Option = Select.Option;
/**
 * 查询表单
 * @extends {PureComponent} - React.PureComponent
 * @reactProps {Function} onQueryMessage - 查询
 * @reactProps {Function} onStoreFormValues - 存储表单值
 * @reactProps {Object} statusList - 状态
 * @return React.element
 */

var formLayout = {
  labelCol: {
    span: 10
  },
  wrapperCol: {
    span: 14
  }
};
var QueryForm = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_PureComponent) {
  _inherits(QueryForm, _PureComponent);

  var _super = _createSuper(QueryForm);

  function QueryForm() {
    var _this;

    _classCallCheck(this, QueryForm);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    _this.state = {
      expandForm: false,
      selectMsgType: ''
    };
    return _this;
  }

  _createClass(QueryForm, [{
    key: "handleSearch",
    value:
    /**
     * 查询表单-查询
     * @param {*} e
     */
    function handleSearch(e) {
      e.preventDefault();
      var onSearch = this.props.onSearch;
      var _this$props = this.props,
          form = _this$props.form,
          onStoreFormValues = _this$props.onStoreFormValues;
      form.validateFields(function (err, fieldsValue) {
        if (_isEmpty(err)) {
          var values = _objectSpread({}, fieldsValue);

          values = {
            startDate: fieldsValue.startDate ? fieldsValue.startDate.format(DEFAULT_DATETIME_FORMAT) : undefined,
            endDate: fieldsValue.endDate ? fieldsValue.endDate.format(DEFAULT_DATETIME_FORMAT) : undefined
          };
          onStoreFormValues(_objectSpread(_objectSpread({}, fieldsValue), values));
        }
      });
      onSearch();
    }
    /**
     * 重置表单
     *
     * @memberof QueryForm
     */

  }, {
    key: "handleFormReset",
    value: function handleFormReset() {
      this.props.form.resetFields();
      this.setState({
        selectMsgType: ''
      });
    }
    /**
     * 多查询条件展示
     */

  }, {
    key: "toggleForm",
    value: function toggleForm() {
      var expandForm = this.state.expandForm;
      this.setState({
        expandForm: !expandForm
      });
    }
    /**
     * 类型值改变时触发
     * @param {string} value
     */

  }, {
    key: "selectMsgChange",
    value: function selectMsgChange(value) {
      this.setState({
        selectMsgType: value
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props$form = this.props.form,
          getFieldDecorator = _this$props$form.getFieldDecorator,
          getFieldValue = _this$props$form.getFieldValue;
      var _this$props2 = this.props,
          statusList = _this$props2.statusList,
          messageTypeList = _this$props2.messageTypeList,
          tenantRoleLevel = _this$props2.tenantRoleLevel;
      var _this$state = this.state,
          expandForm = _this$state.expandForm,
          selectMsgType = _this$state.selectMsgType;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Form, {
        className: "more-fields-search-form"
      }, /*#__PURE__*/React.createElement(Row, Object.assign({}, SEARCH_FORM_ROW_LAYOUT, {
        type: "flex",
        gutter: 24,
        align: "bottom"
      }), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('cmsg.common.view.type').d('类型')
      }, formLayout), getFieldDecorator('messageTypeCode')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true,
        onChange: this.selectMsgChange
      }, messageTypeList && messageTypeList.map(function (item) {
        return /*#__PURE__*/React.createElement(Option, {
          value: item.value,
          key: item.value
        }, item.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('cpaas.common.status').d('状态')
      }, formLayout), getFieldDecorator('trxStatusCode')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true
      }, statusList && statusList.map(function (item) {
        return /*#__PURE__*/React.createElement(Option, {
          value: item.value,
          key: item.value
        }, item.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('cmsg.messageQuery.model.messageQuery.subject').d('主题')
      }, formLayout), getFieldDecorator('subject')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, Object.assign({}, FORM_COL_4_LAYOUT, {
        className: "search-btn-more"
      }), /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Button, {
        onClick: this.toggleForm
      }, expandForm ? intl.get('cpaas.common.button.collected').d('收起查询') : intl.get('cpaas.common.button.viewMore').d('更多查询')), /*#__PURE__*/React.createElement(Button, {
        onClick: this.handleFormReset
      }, intl.get('cpaas.common.button.reset').d('重置')), /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        htmlType: "submit",
        onClick: this.handleSearch
      }, intl.get('cpaas.common.button.search').d('查询'))))), /*#__PURE__*/React.createElement(Row, Object.assign({}, SEARCH_FORM_ROW_LAYOUT, {
        style: {
          display: expandForm ? '' : 'none'
        },
        type: "flex",
        gutter: 24,
        align: "bottom"
      }), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('cmsg.messageQuery.model.messageQuery.serverCode').d('账号代码')
      }), getFieldDecorator('serverCode')( /*#__PURE__*/React.createElement(Input, {
        trim: true,
        typeCase: "upper",
        inputChinese: false
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('cmsg.messageQuery.model.messageQuery.receiver').d('接收人')
      }, formLayout), getFieldDecorator('receiver')(selectMsgType === 'WEB' ? /*#__PURE__*/React.createElement(Lov, {
        code: "CMSG.SITE.USER"
      }) : /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('cmsg.messageQuery.model.messageQuery.startDate').d('发送时间从')
      }, formLayout), getFieldDecorator('startDate')( /*#__PURE__*/React.createElement(DatePicker, {
        showTime: true,
        placeholder: "",
        format: getDateTimeFormat(),
        disabledDate: function disabledDate(currentDate) {
          return getFieldValue('endDate') && moment(getFieldValue('endDate')).isBefore(currentDate, 'day');
        }
      }))))), /*#__PURE__*/React.createElement(Row, Object.assign({}, SEARCH_FORM_ROW_LAYOUT, {
        style: {
          display: expandForm ? '' : 'none'
        },
        type: "flex",
        gutter: 24,
        align: "bottom"
      }), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('cmsg.messageQuery.model.messageQuery.endDate').d('发送时间至')
      }), getFieldDecorator('endDate')( /*#__PURE__*/React.createElement(DatePicker, {
        showTime: true,
        placeholder: "",
        format: getDateTimeFormat(),
        disabledDate: function disabledDate(currentDate) {
          return getFieldValue('startDate') && moment(getFieldValue('startDate')).isAfter(currentDate, 'day');
        }
      })))), !tenantRoleLevel && /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('entity.tenant.tag').d('租户')
      }, formLayout), getFieldDecorator('tenantId')( /*#__PURE__*/React.createElement(Lov, {
        code: "CPFM.TENANT"
      })))))));
    }
  }]);

  return QueryForm;
}(PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "handleSearch", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "handleSearch"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleFormReset", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "handleFormReset"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "toggleForm", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "toggleForm"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "selectMsgChange", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "selectMsgChange"), _class2.prototype)), _class2)) || _class);
export { QueryForm as default };